import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    replayList: [{
        id: 1,
        name: 'zs',
        comment: [{
            content: 'zs评论 1',
            replays: [{
              id: 2,
              name: 'ls',
              content: 'li评论zs 1',
              commentTime: '2022/1/9 14:30',
            }]
          },
          {
            content: 'zs评论 2',
            replays: []
          },
        ],
        commentTime: '2022/1/9 14:00',

      },
      {
        id: 2,
        name: 'ls',

        comment: [{
            content: 'ls评论 1',
            replays: []
          },
          {
            content: 'ls评论 2',
            replays: [

            ]
          },
        ],

        commentTime: '2022/1/9 14:30',
      }
    ],
    id: 2,
    // expands: []
  },
  getters: {

  },
  mutations: {
    inputChange(state, inputValue) {
      // debugger
      // console.log(inputValue)
      const obj = {
        id: ++state.id,
        name: Math.random().toFixed(2) + 'abc',
        comment: [{
          content: inputValue,
          replays: []
        }],
        commentTime: new Date().getFullYear() + '/' + new Date().getMonth() + '/' + new Date().getDate() + ' ' + new Date().getHours() + ':' + new Date().getMinutes()
      }
      state.replayList.unshift(obj)
      console.log(state.replayList)
    },
    // 删除评论
    deleteComment(state, params) {
      // console.log(params)
      var id = state.replayList.findIndex((item) => {
        return item.id === params.id
      })
      state.replayList[id].comment[params.index].content = '该评论已删除！'
      // console.log(state.replayList)
    },
    deleteComment1(state, params) {
      var id = state.replayList.findIndex((item) => {
        return item.id === params.id
      })
      state.replayList[id].comment[params.index].replays[params.index1].content = '该评论已删除！'
    },
    // 增加回复
    inputChange1(state, value) {
      console.log(value);
      const obj = {
        id: 2,
        name: 'ls',
        content: value.commentValue,
        commentTime: new Date().getFullYear() + '/' + new Date().getMonth() + '/' + new Date().getDate() + ' ' + new Date().getHours() + ':' + new Date().getMinutes()
      }
      if (state.replayList[value.index0].comment[value.index].replays) {
        console.log(11)
        state.replayList[value.index0].comment[value.index].replays.unshift(obj)
      }


    }
  },
  actions: {},
  modules: {}
})